#include <STC15F2K60S2.H>
#include "Delay.h"


unsigned char code NixieTable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
typedef unsigned char uint8_t;
#define Nixie_W 0xd0
#define Nixie_D 0xf0
#define LED 0x80
#define RELAY 0xa0

/**********************************************************************************************/
/**锁存器初始化
	* @brief  选择锁存器；继电器，蜂鸣器0xa0；LED0x80；数码管位选端0xd0，段选端0xf0；
	* @param  latch选择相对应的锁存器； P0Data控制P0电平；蜂鸣器P0^6高电平打开;
						继电器P0^5高电平打开；
	* @retval  无
	*/
void Latch_Init(uint8_t latch,uint8_t P0Data)
{

	
	P2=latch;
//		if(latch == Nixie_D)
//	{
//		P0=0xff;
//	}
	P0=P0Data;
	P2=0x00;
}
/**********************************************************************************************/

/**********************************************************************************************/
//数码管显示
void Nixie_Show(uint8_t position,uint8_t number)
{
	
	
	switch(position)
	{
		case 1:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 2:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 3:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 4:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 5:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 6:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 7:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
		case 8:Latch_Init(Nixie_W,0x01<<(position-1));Latch_Init(Nixie_D,NixieTable[number]);break;
	}
	Delay(1);
	Latch_Init(Nixie_W,0x00);
}


/**********************************************************************************************/

void main()
{
//	int i = 0;int c = 1;
//	Latch_Init(0xa0,0x00);

//	while(++i)
//	{
//		if(10==i)
//		i=1;
//		Nixie_Show(c,i);
//		Latch_Init(LED,i);
//		c++;
//		if(9==c)
//				c=1;
//		Delay(5000);
//				}
//	Latch_Init(0xa0,0x00);
	unsigned char i = 123;
	Nixie_Show(1,i/100);
	Nixie_Show(2,i/10%10);
	Nixie_Show(3,i%10);
	
	
}
